package com.baboba.rummy.web.client;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import com.baboba.rummy.cards.Card;
import com.baboba.rummy.cards.CardBitMap;
import com.baboba.rummy.cards.CardComparator;
import com.baboba.rummy.cards.CardFactory;
import com.baboba.rummy.game.IceBreaker;
import com.baboba.rummy.web.client.card.CardListView;
import com.baboba.rummy.web.client.card.IceBreakView;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class RummyWeb implements EntryPoint {
	
	private List<Card> currentCards = new  LinkedList<Card>();
	
	@Override
	public void onModuleLoad() {
		LinkedList<Card> allCards = CardFactory.generateRandomCardsAsList();
		
		VerticalPanel topContainer = new VerticalPanel();
		
		for (int i=1;i<=14;i++){
			currentCards.add(allCards.getFirst());
			allCards.removeFirst();
		}
		
		Collections.sort(currentCards, new CardComparator());
		CardListView cardListView = new CardListView(currentCards);
		
		final IceBreakView iceBreakView = new IceBreakView();
		
		Button button = new Button("Ice Break");
		button.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				iceBreakView.showIceBreak(IceBreaker.awkwardBreak(new CardBitMap(currentCards)));
			}
			
		});
		
		topContainer.add(cardListView);
		topContainer.add(button);
		topContainer.add(iceBreakView);
		RootLayoutPanel.get().add(topContainer);
	}
}
